Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

.specify/extensions/git/scripts/bash/git-common.sh bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 2.22 KB

T8b949e#!/usr/bin/env bash
T8b949e# Git-specific common functions for the git extension.
T8b949e# Extracted from scripts/bash/common.sh — contains only git-specific
T8b949e# branch validation and detection logic.

T8b949e# Check if we have git available at the repo root
has_gitTff7b72(Tff7b72) Tff7b72{
Tffa657local Te6edf3repo_rootTff7b72=Ta5d6ff"Tffd700${Te6edf31Tff7b72:-Tff7b72$(Tffa657pwdTff7b72)Tffd700}Ta5d6ff"
Tff7b72{ Tff7b72[ -d Ta5d6ff"Te6edf3$repo_rootTa5d6ff/.gitTa5d6ff" Tff7b72] Tff7b72|| Tff7b72[ -f Ta5d6ff"Te6edf3$repo_rootTa5d6ff/.gitTa5d6ff" Tff7b72]Tb4b4b4; Tff7b72} Tff7b72&& Tffea00\
Tffa657command -v git >/dev/null T79c0ff2>Tb4b4b4&T79c0ff1 Tff7b72&& Tffea00\
git -C Ta5d6ff"Te6edf3$repo_rootTa5d6ff" rev-parse --is-inside-work-tree >/dev/null T79c0ff2>Tb4b4b4&T79c0ff1
Tff7b72}

T8b949e# Strip a single optional path segment (e.g. gitflow "feat/004-name" -> "004-name").
T8b949e# Only when the full name is exactly two slash-free segments; otherwise returns the raw name.
spec_kit_effective_branch_nameTff7b72(Tff7b72) Tff7b72{
Tffa657local Te6edf3rawTff7b72=Ta5d6ff"Te6edf3$1Ta5d6ff"
Tff7b72if Tff7b72[Tff7b72[ Ta5d6ff"Te6edf3$rawTa5d6ff" Tff7b72=~ ^Tff7b72(Tff7b72[^/Tff7b72]+Tff7b72)/Tff7b72(Tff7b72[^/Tff7b72]+Tff7b72)$ Tff7b72]Tff7b72]Tb4b4b4; Tff7b72then
Tffa657printf Ta5d6ff'%s\n' Ta5d6ff"Tffd700${Te6edf3BASH_REMATCHTb4b4b4[2]Tffd700}Ta5d6ff"
Tff7b72else
Tffa657printf Ta5d6ff'%s\n' Ta5d6ff"Te6edf3$rawTa5d6ff"
Tff7b72fi
Tff7b72}

T8b949e# Validate that a branch name matches the expected feature branch pattern.
T8b949e# Accepts sequential (###-* with >=3 digits) or timestamp (YYYYMMDD-HHMMSS-*) formats.
T8b949e# Logic aligned with scripts/bash/common.sh check_feature_branch after effective-name normalization.
check_feature_branchTff7b72(Tff7b72) Tff7b72{
Tffa657local Te6edf3rawTff7b72=Ta5d6ff"Te6edf3$1Ta5d6ff"
Tffa657local Te6edf3has_git_repoTff7b72=Ta5d6ff"Te6edf3$2Ta5d6ff"

T8b949e# For non-git repos, we can't enforce branch naming but still provide output
Tff7b72if Tff7b72[Tff7b72[ Ta5d6ff"Te6edf3$has_git_repoTa5d6ff" !Tff7b72= Ta5d6ff"true" Tff7b72]Tff7b72]Tb4b4b4; Tff7b72then
Tffa657echo Ta5d6ff"[specify] Warning: Git repository not detected; skipped branch validation" >Tb4b4b4&T79c0ff2
Tff7b72return T79c0ff0
Tff7b72fi

Tffa657local branch
Te6edf3branchTff7b72=Tff7b72$(spec_kit_effective_branch_name Ta5d6ff"Te6edf3$rawTa5d6ff"Tff7b72)

T8b949e# Accept sequential prefix (3+ digits) but exclude malformed timestamps
T8b949e# Malformed: 7-or-8 digit date + 6-digit time with no trailing slug (e.g. "2026031-143022" or "20260319-143022")
Tffa657local Te6edf3is_sequentialTff7b72=Tffa657false
Tff7b72if Tff7b72[Tff7b72[ Ta5d6ff"Te6edf3$branchTa5d6ff" Tff7b72=~ ^Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff3,Tff7b72}- Tff7b72]Tff7b72] Tff7b72&& Tff7b72[Tff7b72[ ! Ta5d6ff"Te6edf3$branchTa5d6ff" Tff7b72=~ ^Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff7Tff7b72}-Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff6Tff7b72}- Tff7b72]Tff7b72] Tff7b72&& Tff7b72[Tff7b72[ ! Ta5d6ff"Te6edf3$branchTa5d6ff" Tff7b72=~ ^Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff7,8Tff7b72}-Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff6Tff7b72}$ Tff7b72]Tff7b72]Tb4b4b4; Tff7b72then
Te6edf3is_sequentialTff7b72=Tffa657true
Tff7b72fi
Tff7b72if Tff7b72[Tff7b72[ Ta5d6ff"Te6edf3$is_sequentialTa5d6ff" !Tff7b72= Ta5d6ff"true" Tff7b72]Tff7b72] Tff7b72&& Tff7b72[Tff7b72[ ! Ta5d6ff"Te6edf3$branchTa5d6ff" Tff7b72=~ ^Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff8Tff7b72}-Tff7b72[T79c0ff0-9Tff7b72]Tff7b72{T79c0ff6Tff7b72}- Tff7b72]Tff7b72]Tb4b4b4; Tff7b72then
Tffa657echo Ta5d6ff"Ta5d6ffERROR: Not on a feature branch. Current branch: Te6edf3$rawTa5d6ff" >Tb4b4b4&T79c0ff2
Tffa657echo Ta5d6ff"Feature branches should be named like: 001-feature-name, 1234-feature-name, or 20260319-143022-feature-name" >Tb4b4b4&T79c0ff2
Tff7b72return T79c0ff1
Tff7b72fi

Tff7b72return T79c0ff0
Tff7b72}

Served by rngit 1.5.1 - Generated in 0.05s